package com.example.project.controller;

import com.example.project.entity.Course;
import com.example.project.mapper.CourseMapper;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Controller
@RequestMapping("/course") //自定义路径
public class CourseController {
    @Resource
    CourseMapper courseMapper;

    @GetMapping("/add_course")
    public String toAddPage( Model model){
        Course course=new Course();
        course.setId(4);
        course.setCourse_id("0004");
        course.setTeacher_name("王五");
        course.setCapacity(30);
        model.addAttribute("courses",course);
        return "release_course";
    }

    @PostMapping("/add_course")
    public String addCourse(Course courses){
        courseMapper.save(courses);
        return "success";
    }

    @GetMapping("/show/{course_id}")
    public String findById(Model model,@PathVariable("course_id") String course_id){
        Course course = courseMapper.findById(course_id);
        model.addAttribute("courses",course);
        return "show_course";
    }
}
